/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.teste;


import br.com.modelo.Departamento;
import br.com.modelo.Funcionarios;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 *
 * @author egberto
 */
public class AdicionaDepartamentoFuncionario {
    public static void main(String args[]){
        EntityManagerFactory factory = Persistence.createEntityManagerFactory("default");
        EntityManager manager = factory.createEntityManager();
        
        manager.getTransaction().begin();
        
        Funcionarios f = new Funcionarios();
        f.setNome("Rafael Faustino");
        
        Departamento d = new Departamento();
        d.setNome("Financeiro");
        d.getFuncionarios().add(f);
        
        manager.persist(f);
        manager.persist(d);
        
        manager.getTransaction().commit();
        
        manager.close();
        factory.close();
        
        
    }
}
